package com.retirement.web.controller.csd;

import java.sql.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.retirement.common.utils.DateUtils;
import com.retirement.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.retirement.common.annotation.Log;
import com.retirement.common.core.controller.BaseController;
import com.retirement.common.core.domain.AjaxResult;
import com.retirement.common.enums.BusinessType;
import com.retirement.csd.domain.OdsHealth;
import com.retirement.csd.service.IOdsHealthService;
import com.retirement.common.utils.poi.ExcelUtil;
import com.retirement.common.core.page.TableDataInfo;

/**
 * 健康信息Controller
 *
 * @author ruoyi
 * @date 2024-03-13
 */
@RestController
@RequestMapping("/csd/health")
public class OdsHealthController extends BaseController
{
    @Autowired
    private IOdsHealthService odsHealthService;

    /**
     * 查询健康信息列表
     */
//    @PreAuthorize("@ss.hasPermi('csd:health:list')")
    @GetMapping("/list")
    public TableDataInfo list(OdsHealth odsHealth)
    {
        if (!SecurityUtils.hasRole("admin")) {
            if (SecurityUtils.hasRole("common")) {
                odsHealth.setUserId(SecurityUtils.getUserId());
            }
        }
        startPage();
        List<OdsHealth> list = odsHealthService.selectOdsHealthList(odsHealth);
        return getDataTable(list);
    }

//    @PreAuthorize("@ss.hasPermi('csd:health:list')")
    @GetMapping("/all")
    public List<OdsHealth> all(OdsHealth odsHealth)
    {
        odsHealth.setRecordDate(DateUtils.getNowDate());
        List<OdsHealth> list = odsHealthService.selectOdsHealthList(odsHealth);
        return list;
    }

    /**
     * 导出健康信息列表
     */
//    @PreAuthorize("@ss.hasPermi('csd:health:export')")
    @Log(title = "健康信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OdsHealth odsHealth)
    {
        List<OdsHealth> list = odsHealthService.selectOdsHealthList(odsHealth);
        ExcelUtil<OdsHealth> util = new ExcelUtil<OdsHealth>(OdsHealth.class);
        util.exportExcel(response, list, "健康信息数据");
    }

    /**
     * 获取健康信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('csd:health:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(odsHealthService.selectOdsHealthById(id));
    }

    /**
     * 新增健康信息
     */
//    @PreAuthorize("@ss.hasPermi('csd:health:add')")
    @Log(title = "健康信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OdsHealth odsHealth)
    {
        return toAjax(odsHealthService.insertOdsHealth(odsHealth));
    }

    /**
     * 修改健康信息
     */
//    @PreAuthorize("@ss.hasPermi('csd:health:edit')")
    @Log(title = "健康信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OdsHealth odsHealth)
    {
        return toAjax(odsHealthService.updateOdsHealth(odsHealth));
    }

    /**
     * 删除健康信息
     */
//    @PreAuthorize("@ss.hasPermi('csd:health:remove')")
    @Log(title = "健康信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(odsHealthService.deleteOdsHealthByIds(ids));
    }
}
